#!/bin/bash
# Convert all markdown presentations to PowerPoint
# This script converts all .MD and .md files in the presentations directory

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
PRESENTATIONS_DIR="$PROJECT_ROOT/presentations"
OUTPUT_DIR="$PROJECT_ROOT/presentations/pptx"

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

echo "Converting all presentations from Markdown to PowerPoint..."
echo "Source: $PRESENTATIONS_DIR"
echo "Output: $OUTPUT_DIR"
echo ""

# Method selection
echo "Select conversion method:"
echo "1) Pandoc (fast, basic formatting)"
echo "2) Python script (better formatting, requires python-pptx)"
read -p "Enter choice [1 or 2]: " method

case $method in
    1)
        CONVERTER="$SCRIPT_DIR/md_to_pptx.sh"
        ;;
    2)
        CONVERTER="python3 $SCRIPT_DIR/md_to_pptx.py"
        ;;
    *)
        echo "Invalid choice, using Pandoc"
        CONVERTER="$SCRIPT_DIR/md_to_pptx.sh"
        ;;
esac

# Find and convert all markdown presentation files
find "$PRESENTATIONS_DIR" -maxdepth 1 -type f \( -name "*.md" -o -name "*.MD" \) | while read -r file; do
    filename=$(basename "$file")
    name="${filename%.*}"
    output="$OUTPUT_DIR/${name}.pptx"
    
    echo "Converting: $filename"
    if [ "$method" = "1" ]; then
        bash "$CONVERTER" "$file" "$output"
    else
        python3 "$SCRIPT_DIR/md_to_pptx.py" "$file" "$output"
    fi
    echo ""
done

echo "✓ All conversions complete!"
echo "PowerPoint files saved to: $OUTPUT_DIR"

